package animator.phantom.renderer.param;

/*
    Copyright Janne Liljeblad

    This file is part of Phantom2D.

    Phantom2D is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Phantom2D is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Phantom2D.  If not, see <http://www.gnu.org/licenses/>.
*/

import java.util.*;
import java.io.*;
import java.awt.geom.Point2D;
import animator.phantom.renderer.ImageOperation;
import animator.phantom.paramedit.AnimValueNumberEditor;
import animator.phantom.paramedit.panel.ParamEditPanel;
import animator.phantom.renderer.parent.TransformClone3D;
import animator.phantom.renderer.param.*;

/** 
* A <code>Vector</code> of  <code>AnimatedValue</code> parameters defining an animated affine transform for a 3D object.
*/ 
public class AnimCoords3D extends AnimatedImageCoordinates
{
	/**
	* Z position of animated object.
	*/
	public AnimatedValue z;
	/**
	* Z scale of animated object.
	*/
	public AnimatedValue zScale;
	/**
	* Anchor point Z coordinate offset from topleft corner of an untransformed rectangular animated object.
	*/
	public AnimatedValue zAnchor;
	/**
	* Z position default value.
	*/
	public static final float zDefault = 0.0f;
	/**
	* Z scale default value.
	*/
	public static final float zScaleDefault = 100.0f;
	/**
	* Anchor point Z coordinate offset default value.
	*/
	public static final float zAnchorDefault = 0.0f;
	/**
	* Rotation on Y axis. Super rotation is rotation on X-axis.
	*/
	public AnimatedValue rotY;
	/**
	* Rotation on Z axis. Super rotation is rotation on X-axis.
	*/
	public AnimatedValue rotZ;

	/**
	* Creates object with default values for all parameters.
	*/
	public AnimCoords3D( ImageOperation iop )
	{
		super( iop );
		this.z = new AnimatedValue(iop, zDefault);
		this.zScale = new AnimatedValue(iop, zScaleDefault);
		this.zAnchor = new AnimatedValue(iop, xAnchorDefault);
		this.rotY = new AnimatedValue(iop, rotationDefault); 
		this.rotZ = new AnimatedValue(iop, rotationDefault);

		hideUnusedParams();
	}

	/**
	* Creates object with specified values.
	*/
	public AnimCoords3D(	ImageOperation iop,
				float Fx,
				float Fy,
				float Fz,
				float FxScale,
				float FyScale,
				float FzScale,
				float FxAnchor,
				float FyAnchor,
				float FzAnchor,
				float FrotX,
				float FrotY, 
				float FrotZ )
	{
		super( 	iop, 
			Fx,
			Fy,
			FxScale,
			FyScale,
			FxAnchor,
			FyAnchor,
			FrotX );

		this.z = new AnimatedValue(iop, Fz);
		this.zScale = new AnimatedValue(iop, FzScale);
		this.zAnchor = new AnimatedValue(iop, FzAnchor);
		this.rotY = new AnimatedValue(iop, FrotY); 
		this.rotZ = new AnimatedValue(iop, FrotZ);

		hideUnusedParams();
	}

	/**
	* Sets all values in given frame.
	*/ 
	public void setValuesForFrame( int frame, float xF, float yF, float zF, float xScaleF, float yScaleF, float zScaleF,
		 float xAnchorF, float yAnchorF, float zAnchorF, float rotXF, float rotYF, float rotZF )
	{
		x.setValue( frame, xF );
		y.setValue( frame, yF );
		z.setValue( frame, zF );
		xScale.setValue( frame, xScaleF );
		yScale.setValue( frame, yScaleF );
		zScale.setValue( frame, zScaleF );
		xAnchor.setValue( frame, xAnchorF );
		yAnchor.setValue( frame, yAnchorF );
		zAnchor.setValue( frame, zAnchorF );
		rotation.setValue( frame, rotXF );
		rotY.setValue( frame, rotYF );
		rotZ.setValue( frame, rotZF );
	}	

	/**
	* Retuns all parameters in Vector. Used internally when registering paramters.
	*/
	public Vector getParamsVector()
	{
		Vector retVec = super.getParamsVector();
		retVec.add( z );
		retVec.add( zScale );
		retVec.add( zAnchor );
		retVec.add( rotY );
		retVec.add( rotZ );
		return retVec;
	}
	
	/**
	* Returns Z scale in normalized form.
	*/
	public float getNormZScale( int frame ){ return zScale.getValue( frame ) / zScaleDefault; }

	/**
	* Returns temporary object used to create movement parent functionality.
	*/
	public TransformClone3D getTransformClone3D( int frame )
	{	
		ImageOperation iop = x.getIOP();
		return new TransformClone3D( 	iop,
						x.getValue( frame ),
						y.getValue( frame ),
						z.getValue( frame ),
						xScale.getValue( frame ),
						yScale.getValue( frame ),
						zScale.getValue( frame ),
						xAnchor.getValue( frame ),
						yAnchor.getValue( frame ),
						zAnchor.getValue( frame ),
						rotation.getValue( frame ),
						rotY.getValue( frame ),
						rotZ.getValue( frame ) );
	}
	/**
	* Sets all params to accept values outside clip area.
	*/
	protected void setAllValuesTypeFreeSet()
	{
		super.setAllValuesTypeFreeSet();
		z.setFreeSet();
		zScale.setFreeSet();
		zAnchor.setFreeSet();
	}

	//--- THese got in and don't come out peacefully, and may even be neede some time
	//--- in the future.
	private void hideUnusedParams()
	{
		this.zAnchor.setHiddenFromKFEditor();
		this.xAnchor.setHiddenFromKFEditor();
		this.yAnchor.setHiddenFromKFEditor();
	}

}//end class
